from PyQt5.QtCore import QObject, pyqtSignal, pyqtSlot, QDateTime
from PyQt5.QtWidgets import QWidget

from sub_threads.sub_t_monitoring_conn import ThreadMonitoringConn
from utils.global_state import GlobalState
from utils.config_manager import ConfigManager
from hal.hardware_manager import HardwareManager

class SignalsControllerCore(QObject):
    aa = pyqtSignal(str, str)
    bb = pyqtSignal(str)
    # para1: print content
    # para2: color: black, red, blue
    print_sys_mon_console = pyqtSignal(str, str)

class ControllerCore(QObject):
    def __init__(self, threadpool, lb_disp_navi_date):
        super(ControllerCore, self).__init__()
        self.thread_pool = threadpool
        self.__dict_main_widgets = lb_disp_navi_date

        self.__init_instance_var()

        self.__restore_settings()

        # self.init_ctrl_state()

        self.__connect()

    # 初始化实例变量（成员变量）
    def __init_instance_var(self):
        self.__global_state = GlobalState()
        self.signals = SignalsControllerCore()
        self.__hal = HardwareManager()

        # 软件开启后，开启监控硬件连接线程
        self.t_monitor_conn = ThreadMonitoringConn()

    # 加载文件中的用户设置
    def __restore_settings(self):
        self.__config_man = ConfigManager()
        self.__config_data = self.__config_man.get_section("controller_core")


    def __connect(self):
        pass


    def init_ctrl_state(self):
        self.on_sig_update_time()
        self.thread_pool.start(self.t_monitor_conn)

    def on_sig_update_time(self):
        # 获取当前日期和时间
        current_date_time = QDateTime.currentDateTime()

        # 格式化日期和时间为字符串
        date_str = current_date_time.toString("yyyy-MM-dd")
        time_str = current_date_time.toString("hh:mm")

        self.__dict_main_widgets["lb_disp_navi_time"].setText(time_str)
        self.__dict_main_widgets["lb_disp_navi_date"].setText(date_str)

        # self.lb_disp_navi_time.setText(time_str)
        # self.lb_disp_navi_date.setText(date_str)

